<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="utf-8"/>
    <title>layui</title>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all"/>
    <link rel="stylesheet" href="/css/public.css" media="all"/>
    <style>
        html, body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
        }

        .layui-table-click {
            background-color: #99BBFF !important;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="layui-elem-field layuimini-search">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">住院号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="patientId" id="patientId" placeholder="输入住院号回车加载"
                                       class="layui-input" value="300002526"></input>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn layui-btn-normal" type="button" id="data-search-btn"><i
                                    class="layui-icon layui-icon-search"></i>查询
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <div class="layui-row layui-col-space6 layui-panel">

            <div class="layui-col-md3">
                <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
            </div>
            <div class="showMessage layui-col-md9">
                <pre class="layui-code"></pre>
            </div>

        </div>

    </div>
</div>

<script src="/lib/layui-v2.5.4/layui.js" charset="utf-8"></script>
<script src="/js/lay-config.js?v=1.0.4" charset="utf-8"></script>

<script>
    layui.use(['form', 'table', 'layer', 'laydate', 'code'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            layer = layui.layer;

        layui.code({
            title: "病历文档结构",
            height: "600px"
        });

        table.render({
            elem: '#currentTableId',
            method: 'post',
            url: '/hwn/findMedicalRecord',
            cols: [ [
                {field: 'id', title: 'ID', sort: true, hide: true},
                {field: 'patientId', title: '住院号', hide: true},
                {field: 'visitId', title: '次数', sort: true, hide: true},
                {field: 'kind', title: '文档名称', width: '44%'},
                {field: 'doctor', title: '医生', width: '20%'},
                {
                    field: 'docDate',
                    title: '创建时间',
                    sort: true,
                    width: '36%',
                    templet: '<div>{{ layui.util.toDateString(d.docDate, "yyyy-MM-dd HH:mm:ss") }}</div>'
                },
            ]],
            size: 'sm',
            skin: 'line',
            height: 'full-160',
            even: true
        });

        $('#patientId').on('keydown', function (event) {
            if (event.keyCode == 13) {
                load($('#patientId').val());
                return false;
            }
        });

        // 监听搜索操作
        $('#data-search-btn').on('click', function (data) {
            load($('#patientId').val());
        });

        function load(patientId) {
            if (patientId != '') {
                //执行搜索重载
                table.reload('currentTableId', {
                    where: {
                        patientId: patientId
                    }
                }, 'data');
            } else {
                layer.msg('请输入正确的住院号！');
                $('#patientId').onfocus;
            }
            return false;
        }

        //监听行单击事件
        table.on('row(currentTableFilter)', function (obj) {
            $('.layui-table-body table.layui-table tbody tr').removeClass('layui-table-click');
            obj.tr.addClass('layui-table-click');
            queryText(obj.data.id);
        });

        function queryText(id) {
            var index = layer.msg('拼命加载中...', {
                icon: 16
                , shade: 0.01,
                time: 0
            });
            $.ajax({
                url: "/hwn/parseMedicalRecordText",
                type: "POST",
                success: function (obj) {
                    layer.close(index);
                    if (obj.code = "0") {
                        var jdata = JSON.stringify(obj.data, null, 4);
                        $(".showMessage").html('<pre class="layui-code">' + obj.data + '</pre>');
                        layui.code({
                            title: "病历文档内容",
                            height: "600px"
                        });
                        $('.layui-code-h3 a').text('转结构').css({'color': "red", "font-weight": "bold"});
                        $('.layui-code-h3 a').on("click", function () {
                            queryMode(id);
                        });
                    } else {
                        layer.msg(obj.msg);
                    }
                },
                data: {
                    id: id
                }
            });
        }

        function queryMode(id) {
            var index = layer.msg('拼命加载中...', {
                icon: 16
                , shade: 0.01,
                time: 0
            });
            $.ajax({
                url: "/hwn/parseMedicalRecord",
                type: "POST",
                success: function (result) {
                    layer.close(index);
                    var jdata = JSON.stringify(result, null, 4);
                    console.log(jdata);
                    $(".showMessage").html('<pre class="layui-code">' + jdata + '</pre>');
                    layui.code({
                        title: "病历文档结构",
                        height: "600px"
                    });
                    $('.layui-code-h3 a').text('转文本').css({'color': "blue", "font-weight": "bold"});
                    $('.layui-code-h3 a').on("click", function () {
                        queryText(id);
                    });
                },
                data: {
                    id: id
                }
            });
        }

    });
</script>

</body>
</html>
